package com.liu.concurrent.sync;

/**
 * 同步代码块 synchronized 修饰类->类锁
 */
public class SyncTest2 implements Runnable {
	public void run() {
		synchronized (SyncTest2.class) {
			syso();
		}
		synchronized (new SyncTest2().getClass()) {
			syso();
		}
		synchronized (this.getClass()) {
			syso();
		}
		synchronized (super.getClass()) {
			syso();
		}
		synchronized (Object.class) {
			syso();
		}
	}

	public static void main(String[] args) throws InterruptedException {
		SyncTest2 syncTest1 = new SyncTest2();
		SyncTest2 syncTest2 = new SyncTest2();
		Thread thread1 = new Thread(syncTest1, "thread1");
		Thread thread2 = new Thread(syncTest2, "thread2");
		thread1.start();
		thread2.start();

		// SyncTest2 syncTest1 = new SyncTest2();
		// Thread thread1 = new Thread(syncTest1, "thread1");
		// Thread thread2 = new Thread(syncTest1, "thread2");
		// thread1.start();
		// thread2.start();
	}

	public void syso() {
		try {
			System.out.println(Thread.currentThread().getName() + "_Start");
			Thread.sleep(10000);
			System.out.println(Thread.currentThread().getName() + "_End");
			System.err.println("-----------------------------------------");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}